如何使用HTTP POST访问服务? 现在,请求默认使用HTTP GET, 但现在我必须将其更改为POST,我该怎样才能实现 这个?我应该对app.config文件进行任何更改吗? 我正在使用.net c#4.0。
ServiceReference2.ServicePortTypeClient svc = new ServiceReference2.ServicePortTypeClient();
//some code
try
{
ServiceReference2.ResponseType res = svc.getData(part);
Console.WriteLine(res);
}
catch (Exception)
{
Console.WriteLine("not authenticated");
}
配置:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="WebServiceUrl" value="http://vissvc-test.e.intra.net/SvcNative/VisService"/>
<add key="LogoutUrl" value="http://login.e.intra.net/internal/logout"/>
</appSettings>
<system.net>
<defaultProxy>
<proxy autoDetect="True"/>
</defaultProxy>
</system.net>
<system.web>
<compilation debug="true"/>
<webServices>
<soapExtensionTypes>
<add type="SoapExtension, MyExtension"/>
</soapExtensionTypes>
</webServices>
</system.web>
<system.serviceModel>
<bindings>
<customBinding>
<binding name="SoapBinding">
<customTextMessageEncoding encoding="UTF-8" messageVersion="Soap11"/>
<httpTransport/>
</binding>
</customBinding>
</bindings>
<extensions>
<behaviorExtensions>
<--! some behavior ---!>
</behaviorExtensions>
<bindingElementExtensions>
<---some behavior extension-->
</bindingElementExtensions>
</extensions>
<behaviors>
<endpointBehaviors>
<behavior name="Behaviour">
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="http://vissvc- test.e.intra.net/SvcNative/VisService "binding="customBinding" bindingConfiguration="SoapBinding" contract="ServiceReference2.ServicePortType" name="VisService" behaviorConfiguration="Behaviour"/>
</client>
</system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</configuration>