DECLARE @Object INT;
DECLARE @Status INT;
DECLARE @Response NVARCHAR(1000);
DECLARE @requestBody NVARCHAR(MAX) = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<HelloWorld xmlns="http://smartbear.com" />
</soap:Body>
</soap:Envelope>'
EXEC sp_OACreate 'WinHttp.WinHttpRequest.5.1', @Object OUT;
EXEC sp_OAMethod @Object, 'Open', NULL, 'POST', 'http://secure.smartbearsoftware.com/samples/testcomplete12/webservices/Service.asmx', 'false'
EXEC sp_OAMethod @Object, 'setRequestHeader', null, 'Host', 'secure.smartbearsoftware.com'
EXEC sp_OAMethod @Object, 'setRequestHeader', null, 'Content-Type', 'text/xml'
DECLARE @len INT = len(@requestBody)
EXEC sp_OAMethod @Object, 'setRequestHeader', null, 'Content-Length', @len
EXEC sp_OAMethod @Object, 'setRequestHeader', null, 'SOAPAction', "http://smartbear.com/HelloWorld"
EXEC sp_OAMethod @Object, 'send', null, @requestBody
EXEC sp_OAGetProperty @Object, 'Status', @Status OUT
EXEC sp_OAGetProperty @Object, 'ResponseText', @Response OUTPUT
EXEC sp_OADestroy @Object
PRINT @Status
PRINT @Response
web etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
web etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
23 Mart 2018
SQL ile Web Servis Kullanmak
http://secure.smartbearsoftware.com/samples/testcomplete12/webservices/Service.asmx adresi üzerindeki demo web servisten HelloWorld metodunu çağıracağız.
Örnek kod aşağıdadır.
13 Aralık 2017
Dotnet Core ile Postgresql
Dotnet Core 2 SDK ve Visual Studio Code kurulu olduğu varsayılmıştır.
Son hali aşağıdaki gibidir.
6) Models adında bir klasör oluşturalım ve içerisine
User.cs sınıfını ekleyelim
ve TestContext.cs ekleyelim
Startup.cs en son hali aşağıdaki gibidir.
8. Projeyi Kaydet Komut satırına
elephantsql.com üzerinden denemek için ücretsiz bir postgresql database alabilirsiniz.
projem.csproj son hali aşağıdaki gibidir.
Konsol açalım
1) Yeni bir dotnet projesi oluşturalım
mkdir projem cd projem dotnet new webapi
2) Kullanacağımız paketleri kuralım
dotnet add package Microsoft.EntityFrameworkCore.Design dotnet add package Microsoft.EntityFrameworkCore.Tools dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL
3)Visual Studio Code ile projeyi açalım.
code .
4) projem.csproj içerisinde Microsoft.EntityFrameworkCore.Tools.DotNet toolunu ekleyelim.
<dotnetclitoolreference include="Microsoft.EntityFrameworkCore.Tools.DotNet" version="2.0.1">
projem.csproj son hali aşağıdaki gibidir.
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.1" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.1" />
</ItemGroup>
</Project>
5) appsettings.Development.json içerisine TestConnection isminde bir bağlantı cümlesi ekleyelim
"ConnectionStrings":{
"TestConnection":"Server=XXX;Port=5432;Database=XXX;User Id=XXX;Password=XXX;"
},
Son hali aşağıdaki gibidir.
{
"ConnectionStrings":{
"TestConnection":"Server=XXX;Port=5432;Database=XXX;User Id=XXX;Password=XXX;"
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
6) Models adında bir klasör oluşturalım ve içerisine
User.cs sınıfını ekleyelim
namespace projem.Models
{
public class User
{
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
}
}
ve TestContext.cs ekleyelim
using Microsoft.EntityFrameworkCore;
namespace projem.Models
{
public class TestContext : DbContext
{
public TestContext(DbContextOptions<TestContext> options) : base(options) { }
public DbSet<User> Users { get; set; }
}
}
7. Sonuncu ve en önemli adım Startup.cs içerisinde ConfigureService metodunun içerisine EntityFrameworkNpgsql() servisini ekleyelim
services.AddEntityFrameworkNpgsql().AddDbContext<testcontext>(opt =>
opt.UseNpgsql(Configuration.GetConnectionString("TestConnection"))
);
Startup.cs en son hali aşağıdaki gibidir.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using projem.Models;
namespace projem
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddEntityFrameworkNpgsql().AddDbContext<testcontext>(opt =>
opt.UseNpgsql(Configuration.GetConnectionString("TestConnection"))
);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
}
}
}
8. Projeyi Kaydet Komut satırına
dotnet ef migrations add InitialCreateile ilk migration oluşturdurk ve
dotnet ef database updateile tarafımızda olan değişiklikeri database üzerinde yansıttık. https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet
9 Ağustos 2017
ASP.NET Core Web Api ile Angular 4 Projesi Oluşturma
Ön Gereksinimler
- Node.js
- Net Core
- Visual Studio Code
1. Proje Oluşturma
Linux'ta "terminal", Windows'ta "komut satırı" açalım.
1.Projemiz için bir klasör oluşturalım.
mkdir projem
2. Projenin içine girelim
cd projem
3. Boş ASP.NET Core projesi açalım.
dotnet new webapi
4. Visul Studio Code ile projeyi açalım.
code .
5.Visual Studio Code ile .csproj dosyasını açalım ve typescript hatalarını kapatmak için özelliği property group içerisine ekleyelim
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
ve wwwroot gibi klasörlerin içerisindeki dosyaları kullanabilmek için
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="*"/>
Varsa aşağıdaki alanı silelim. Çünkü StaticFiles paketini kullandığımız için aşağıdaki özelliğe gerek kalmayacak.
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
komutunu ekleyelim .csproj aşağıdaki gibi olacaktır.
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="*"/>
</ItemGroup>
</Project>
6.Startup.cs içerisinde Configure metodunun içerisi aşağıdaki gibi değiştirelim.
app.Use(async (context, next) => {
await next();
if (context.Response.StatusCode == 404 &&
!Path.HasExtension(context.Request.Path.Value) &&
!context.Request.Path.Value.StartsWith("/api/")) {
context.Request.Path = "/index.html";
await next();
}
});
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseMvcWithDefaultRoute();
7. Komut satırından eksik paketleri kurmak için aşağıdaki komutu çalıştırın
dotnet restore 8. Projeyi build etmek için aşağıdaki komutu kullanın
dotnet build
9. Projeyi çalıştırmak için aşağıdaki komutu kullanın
dotnet run
http://localhost:5000/api/values adresine girip çalışıp çalışmadığını kontrol edebiliriz.
Angular Projesi Oluşturmak
1. Öncelikle angular 4 kurmamız gerekiyor. Angular 4 ü global kurmak için aşağıdaki satırı komut satırında çalıştıralım.
npm install @angular/cli --global
ng new gecicKlasor --skip-install
3. src/app/app.module.ts içerisne Http ve Forms modüllerini ekleyelim.
import { FormsModule } from '@angular/forms';
import {HttpModule} from '@angular/http';
imports: [
BrowserModule,
FormsModule,
HttpModule
],
4. .angular-cli.json dosyasını açın ve "outDir":"wwwroot" olarak seçin. Böylece angular build edildiğinde web api nin statik dosylarıyla aynı klasöre çıkmış olacak.
"outDir": "wwwroot",
5. Angular içerisinde web servisi çağıralım. Bunun için "src/app/app.component.ts" dosyasını açarak aşağıdaki gibi web servisi çağıralım.
import { Component, OnInit } from '@angular/core';
import { Http } from '@angular/http';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
constructor(private _httpService:Http){}
apiValues:string[] = [];
ngOnInit(){
this._httpService.get('/api/values').subscribe(values=>{
this.apiValues = values.json() as string[];
});
}
}
Ve "src/app/app.component.html" dosyasını aşağıdaki gibi değiştirelim.
<h1>Web Api den gelen yanıt</h1>
<ul *ngFor="let value of apiValues">
<li>{{value}}</li>
</ul>
6. Şimdi angular içerisindeki eksik paketleri kuralım ve build edelim. Bunun için komut satırında projenin olduğu klasöre girerek aşağıdaki komutları yazalım.
npm install
ile eksik paketler kuruluyor
ng build
ile angular build ediliyor.
Artık projemiz hazır komut satırından
dotnet run
yazarak projeyi çalıştıralım. Ve localhost:5000 i tarayıcıdan açalım.
Sonuç olarak tarayıcı da şağıdaki ekranı görmeniz gerekiyor.
Geliştirirken Kolaylık Sağlayan Yöntemler
Normalde yukarıdaki gibi kullanmak istersek her değişiklik için angular ve dotnet projesini build etmemiz gerekiyor. Aşağıdaki işlemleri yaparak her yeni değişiklikte proje kendi kendini build edip tekrar çalışacaktır.
1. Angular ile yapılan değişiklikleri canlı görmek için ng serve komutunu kullanmalıyız ve burada tarayıcıdan localhost:4200 varsayılan olarak kullanılıyor. API nin çalıştığı port 5000 olmasına rağmen varsayılan modda localhost:4200/api yolunu proje kontrol edecekt. Bunu 5000 portu yapmak için proje klasörü içerisinde "proxy.config.json" dosyasını oluşturalım. Ve içerisini aşağıdaki gibi yazalım.
{
"/api": {
"target": "http://localhost:5000",
"secure": false
}
}
2. ASP.NET Core için otomatik derlemeyi aktif etmek için "Microsoft.DotNet.Watcher.Tools" paketini projeye eklemeliyiz. Bunun için .csproj içerisine paketi aşağıdaki gibi ekleyeceğiz.
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="1.0.0" />
</ItemGroup>
.csproj son hali aşağıdaki gibidir.
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="*"/>
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="1.0.0" />
</ItemGroup>
</Project>
Daha sonra yeni eklediğimiz paket için komut satırı üzerinden "dotnet restore" komutunu yazalım.
3. Angular ve ASP.NET Core uygulamalarını izleme modunda açalım.
ASP.NET Core için
dotnet watch run
Angular için ayrı bir komut satırında
ng serve --proxy-config proxy.config.json
yazarak projeyi başlatalım.
Artık tarayıcıda localhost:4200 ü kullanacağız. Ve birisinde yaptığımız değişiklik otomatik olarak ekrana yansıyacak. Burada dotnet build ettiği çok kısa gecikme olabilir.
Şimdi test edersek
Projede "Controllers/ValuesControllers.cs" içerisinde Get metodunu aşağıdaki gibi değiştirip kaydedelim.
// GET api/values
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1" };
}
"src/app/app.component.html" dosyasının içeriğini aşağıdaki gibi değiştirelim ve kaydedelim.
<h1>Bu alan değiştirildi</h1>
<ul *ngFor="let value of apiValues">
<li>{{value}}</li>
</ul>
Tekrar localhost:4200 e baktığımızda aşağıdaki gibi değişikliklerin ekrana yansıdığını göreceğiz.
Kaynak : How to build an Angular Application with ASP.NET Core in Visual Studio 2017, visualized
21 Nisan 2017
Web Sayfana Matematik Denklemleri Ekle
MathJax kütüphanesi ile sayfamıza tex komutlarını ekleyeceğiz.
1. body kapanış tagının altına aşağıdaki script kodlarını ekleyeceğiz.
1. body kapanış tagının altına aşağıdaki script kodlarını ekleyeceğiz.
<script type="text/x-mathjax-config">
MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
2. Daha sonra sayfamızda görmek istediğimiz denklemleri http://docs.mathjax.org/en/latest/mathjax.html adresindeki dökümanlar yardımıyla ekleneecek.
Tamamlanmış html aşağıdaki gibidir.
<html lang="tr">
<head>
<meta charset="utf-8">
<title>MathJax TeX Test Page</title>
</head>
<body>
$a \ne 0$ için \(ax^2 + bx + c = 0\) denkleminin genel çözümü aşağıdaki gibidir.
$$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$
<script type="text/x-mathjax-config">
MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
</body>
</html>
$a \ne 0$ için \(ax^2 + bx + c = 0\) denkleminin genel çözümü aşağıdaki gibidir.
$$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$
Kaydol:
Kayıtlar (Atom)

