您好,我正在使用 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 消息传递到服务端点。
例如
<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 消息,您应该使用服务端点定义并使用 some tooling生成有效请求。
此外,您不应该将数据发送到地址中包含 ?wsdl
的端点地址。它应该只是端点地址。
关于web-services - 如何使用 POSTMAN 测试 wcf soap 服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45456588/