我在.net应用程序中使用了Web服务,并且在Web服务上调用方法给我以下错误:
System.ServiceModel.ProtocolException
HResult=0x80131501
Message=The remote server returned an unexpected response: (400) Bad Request.
Source=mscorlib
StackTrace:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
调用Web服务的代码如下:
testws.B2BServiceClient b2BServiceClient = new testws.B2BServiceClient();
testws.CancelRequest cancelRequest = new testws.CancelRequest();
cancelRequest = new testws.CancelRequest
{
Service_ID = "test_service_id",
Provider_Ref = "test_provider_ref"
};
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;
b2BServiceClient.ClientCredentials.UserName.UserName = "myusername";
b2BServiceClient.ClientCredentials.UserName.Password = "mypasssword";
testws.Response response = b2BServiceClient.CancelService(cancelRequest);
这是来自web.config的摘录
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_testservice">
<security mode="Transport">
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://endpointurl" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_testservice" contract="testws.testservice" name="BasicHttpBinding_testservice"/>
</client>
</system.serviceModel>
此外,我尝试按以下方式从SoapUI发出请求:
<soapenv:Header>
<wsse:Security SOAP-ENV:mustUnderstand = "1" xmlns:wsse = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken xmlns:wsse = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:Username>myusername</wsse:Username>
<wsse:Password Type = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">mypassword</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</SOAP-ENV:Header>
<soapenv:Body>
<tem:CancelService>
<!--Optional:-->
<tem:request>
<!--Optional:-->
<mod:Service_ID>test_service_id</mod:Service_ID>
<mod:Provider_Ref>test_provider_ref</mod:Provider_Ref>
</tem:request>
</tem:CancelService>
</soapenv:Body>
</soapenv:Envelope>
在SoapUI中这样做会给我HTTP / 1.1 500 Internal Server Error
这基本上意味着通过SoapUI发出的请求正在到达服务器。我需要怎么做才能在我的.net应用程序中至少得到相同的错误。
还有,是否可以捕获.net中传出的肥皂请求?