如何使用 SOAPUI 访问 Web 服务的不同方法
How to access to differents methods of webservice with SOAPUI
我尝试使用 SOAP UI 访问我的网络方法,但它仅适用于第一个,我不明白为什么。
我的网络服务方法:
[SoapHeader ("AuthenticationInfo", Required=true)]
[WebMethod(EnableSession = true)]
public string HelloWorld()
{
if (!(AuthenticationInfo.Username == "test" && AuthenticationInfo.Password == "test"))
{
throw new Exception();
// I put that in the aim to get an error, I'll modify this later
}
return "OK";
}
[SoapHeader("AuthenticationInfo", Required = true)]
[WebMethod]
public string Authenticate(string MethodName)
{
if (!(AuthenticationInfo.Username == "test" && AuthenticationInfo.Password == "test")
{
throw new Exception();
}
else
{
HelloWorld();
}
return "aaaa";
}
[WebMethod]
public int Calcul(int a, int b)
{
return a+b ;
}
当我将此 XML 放入 SOAP UI 时:
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<AuthHeader xmlns="http://tempuri.org/">
<Username>test</Username>
<Password>test</Password>
<key>string</key>
</AuthHeader>
</soap:Header>
<soap:Body>
<HelloWorld xmlns="http://tempuri.org/" />
</soap:Body>
</soap:Envelope
它完美运行,我得到了 HelloWord() 方法的 return。
但是如果我输入:
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Calcul xmlns="http://tempuri.org/">
<a>1</a>
<b>1</b>
</Calcul>
</soap:Body>
</soap:Envelope>
它再次调用 HelloWorld() 方法。我在 SOAP UI 中使用的 URL 是:"http://localhost:62353/MyWebService.asmx", so I try a new request with the last XML at the URL "http://localhost:62353/MyWebService.asmx/Calcul" 并且出现错误。
你有我的想法吗?我可能以错误的方式使用 SOAP UI 吗?
回复 Kosala W :
我得到了一个 UI ,我可以在其中单击方法。 calcul 方法仅适用于此处,因为此方法不需要 SoapHeader。
这是回复:
当您在 SOAP UI 中指定 URL 时,您需要像这样在末尾添加 ?wsdl :http://localhost:62353/MyWebService.asmx?wsdl
然后我在 SOAP UI 中刷新项目所有的方法都出现了
我尝试使用 SOAP UI 访问我的网络方法,但它仅适用于第一个,我不明白为什么。
我的网络服务方法:
[SoapHeader ("AuthenticationInfo", Required=true)]
[WebMethod(EnableSession = true)]
public string HelloWorld()
{
if (!(AuthenticationInfo.Username == "test" && AuthenticationInfo.Password == "test"))
{
throw new Exception();
// I put that in the aim to get an error, I'll modify this later
}
return "OK";
}
[SoapHeader("AuthenticationInfo", Required = true)]
[WebMethod]
public string Authenticate(string MethodName)
{
if (!(AuthenticationInfo.Username == "test" && AuthenticationInfo.Password == "test")
{
throw new Exception();
}
else
{
HelloWorld();
}
return "aaaa";
}
[WebMethod]
public int Calcul(int a, int b)
{
return a+b ;
}
当我将此 XML 放入 SOAP UI 时:
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<AuthHeader xmlns="http://tempuri.org/">
<Username>test</Username>
<Password>test</Password>
<key>string</key>
</AuthHeader>
</soap:Header>
<soap:Body>
<HelloWorld xmlns="http://tempuri.org/" />
</soap:Body>
</soap:Envelope
它完美运行,我得到了 HelloWord() 方法的 return。 但是如果我输入:
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Calcul xmlns="http://tempuri.org/">
<a>1</a>
<b>1</b>
</Calcul>
</soap:Body>
</soap:Envelope>
它再次调用 HelloWorld() 方法。我在 SOAP UI 中使用的 URL 是:"http://localhost:62353/MyWebService.asmx", so I try a new request with the last XML at the URL "http://localhost:62353/MyWebService.asmx/Calcul" 并且出现错误。
你有我的想法吗?我可能以错误的方式使用 SOAP UI 吗?
回复 Kosala W : 我得到了一个 UI ,我可以在其中单击方法。 calcul 方法仅适用于此处,因为此方法不需要 SoapHeader。
这是回复:
当您在 SOAP UI 中指定 URL 时,您需要像这样在末尾添加 ?wsdl :http://localhost:62353/MyWebService.asmx?wsdl
然后我在 SOAP UI 中刷新项目所有的方法都出现了