我需要连接到一个web服务,这是我拥有的所有信息:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:env="http://address.provided.by.the.company.es"> <soapenv:Header> <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> <wsse:UsernameToken wsu:Id="UsernameToken-5"> <wsse:Username>Username</wsse:Username> <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">Password</wsse:Password> </wsse:UsernameToken> </wsse:Security> </soapenv:Header> <soapenv:Body> <env:functionIshouldcall> <env:parameter1></env:parameter1> </env:functionIshouldcall> </soapenv:Body> </soapenv:Envelope>这就是我到目前为止所做的:
我该怎么做?提前谢谢。
发布于 2017-09-24 19:56:27
如果您需要添加凭据,这可能是一个很好的起点;我猜您可能不得不这样做,因为您得到了它们。添加凭据的部分如下:
UsernameToken userToken = new UsernameToken(userName, password, PasswordOption.SendHashed);
Service1 serviceProxy = new Service1();
SoapContext requestContext = serviceProxy.RequestSoapContext;
requestContext.Security.Tokens.Add(userToken);简言之:
Microsoft.Web.Services2.Security.Tokens命名空间)中来添加凭据。serviceProxy)RequestSoapContext获得对其请求头的访问此外,我认为您可以跳过地址中的"?wsdl“部分,因为它引用了web服务规范。完成上述操作后,您可以尝试调用该函数并查看所有操作的结果:如果该函数必须返回某项内容,请检查它是否符合您的预期。
当然,不要忘记将您的代码放在一个try-catch块中,因为您可能需要检查一些异常,看看可能出了什么问题。
https://stackoverflow.com/questions/46393532
复制相似问题