如何使用POSTMAN测试WCF SOAP服务?

3

您好,我正在使用WCF开发XML Soap服务。我的要求是更新一些数据库表。我有一个方法可以更新数据库中的值。下面是我的服务。

  [ServiceContract]
public interface IOpportunity
{
    [OperationContract]
    [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Xml, UriTemplate = "postmethod/updateOpportunity")]
    bool updateOpportunity(opportunityActivity obj);
}
[DataContract]
public class opportunityActivity
{
    [DataMember]
    public string opportunityID { get; set; }
    [DataMember]
    public string opportunityStatus { get; set; }
    [DataMember]
    public string opportunityserviceType { get; set; }
}

找不到方法

以下是我的XML。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:s="http://localhost:39512/Opportunity.svc">
   <soapenv:Header/>
   <soapenv:Body>
      <s:request>
       <opportunityID>1-1D5SJX</opportunityID>
       <opportunityStatus>Completed</opportunityStatus>
       <opportunityserviceType>LEASE_REQUEST</opportunityserviceType>
      </s:request>
   </soapenv:Body>
</soapenv:Envelope>

当我按照上面所示的方式尝试时,我会得到400错误请求错误。请问我是否遵循正确的测试方法?如果我做错了,请有人纠正我。任何帮助都将不胜感激。谢谢。

这是不正确的 - 你不能手动构建SOAP请求。使用一些工具来为您完成它。 - tom redfern
1个回答

2
你需要将一个SOAP消息传递到服务端点。例如:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:s="http://myNamespace/">
   <soapenv:Header/>
   <soapenv:Body>
      <s:request>
          ....
      </s:request>
   </soapenv:Body>
</soapenv:Envelope>

要获取SOAP消息,您应该使用服务端点定义并使用某些工具生成有效请求。
此外,您不应该将数据发送到带有?wsdl的端点地址作为地址的一部分。它应该只是端点地址。

谢谢Tom。xmlns:s="http://myNamespace/" 应该被替换为 xmlns:s="http://RayaSoapService/",对吗? - Niranjan Godbole
@NiranjanGodbole 这取决于您如何定义您的终端点。手动从头开始创建SOAP请求非常困难。使用工具让它为您完成要容易得多。 - tom redfern
好的,谢谢。当我运行应用程序时,我缺少方法名称。请问我缺少什么?我已经在上面附上了截图。 - Niranjan Godbole
@NiranjanGodbole - 你在运行什么应用程序?如果是SOAPUI,那么看看这个链接:https://www.soapui.org/soap-and-wsdl/working-with-wsdls.html - tom redfern
@NiranjanGodbole - 同一个WCF应用程序。当我运行它时,它应该列出方法名称,对吗? - 是的,这是另一种获取端点SOAP请求的方法。如果没有列出来,则您的服务存在问题。您应该单独为此问题创建一个新的问题。 - tom redfern

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接