我需要连接一个Web服务,这就是我拥有的所有信息:
https://www.nameofthecompany.es:8443/webservices/functionIshouldcall?wsdl
电话示例:
<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>
我知道这个函数返回一个字符串;
这是我到目前为止所做的:
创建一个服务引用,只添加第1点中给出的WSDL地址。
创建了一个webservice实例,并使用所有需要的参数调用该函数但不是标头的用户和密码。
我该怎么办? 提前谢谢。
答案 0 :(得分:0)
This可能是一个很好的起点;我的猜测是你可能不得不,因为你以某种方式得到它们。 您添加凭据的部分如下所示:
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块中,因为您可能需要检查一些异常并查看可能存在的错误。