IService1.csページ:-
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "Json/{id}")]
string myfun(string id);
Service1.csページ:-
public string myfun(string id)
{
string ConnectString = "server=localhost;database=test_local;integrated security=SSPI";
string QueryString = "select * from tbl_af_register where id=" + id;
SqlConnection myConnection = new SqlConnection(ConnectString);
SqlDataAdapter da = new SqlDataAdapter(QueryString, myConnection);
DataSet ds = new DataSet();
da.Fill(ds, "TestName");
string i = ds.Tables[0].Rows[0]["name"].ToString();
return "your name is " + i;
}
Web.Configファイル内:-
->'system.serviceModel'セクション
<system.serviceModel>
<services>
<service name="WcfService2.Service1">
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address ="" binding="webHttpBinding" contract="WcfService2.IService1" behaviorConfiguration="web">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
</endpoint>
</service>
</services>
web.configの「behaviors」セクション:-
<behaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
注:-この名前「web」は-> BehaviorConfiguration="web"と同じである必要があります