gpt4 book ai didi

wcf - 无法通过邮件到达 WCF 休息端点

转载 作者:行者123 更新时间:2023-12-03 04:39:13 27 4
gpt4 key购买 nike

我正在尝试创建在 Azure Web 角色中托管的 WCF 服务。该服务必须能够通过 SOAP 和休息来访问。

我一直在阅读一些文章,并且能够创建(或者至少我是这么认为)具有所有规范的服务。

我想做的是通过 SoapUI 项目使用我的其余端点,使用带有所有参数的查询字符串执行 POST,但是当我运行该项目时,我得到的响应是:

The server encountered an error processing the request. The exception message is 'Error in deserializing body of request message for operation 'CPlano'. The OperationFormatter could not deserialize any information from the Message because the Message is empty (IsEmpty = true).'

这是我的 Web.Config 的一部分:

<bindings>
<webHttpBinding>
<binding name="webBinding" maxReceivedMessageSize ="50000000" maxBufferPoolSize="50000000">
<readerQuotas maxDepth="500000000" maxArrayLength="500000000" maxBytesPerRead="500000000"
maxNameTableCharCount="500000000" maxStringContentLength="500000000"/>
<security mode="None" />
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="RestBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="Namespace.CService" behaviorConfiguration="ServiceBehavior">
<endpoint name="RESTEnpoint" contract="Namespace.ICService" binding="webHttpBinding" bindingConfiguration="webBinding" bindingNamespace="http://www.example.com/" address="rest" behaviorConfiguration="RestBehavior" />
<endpoint name="SOAPEndpoint" contract="Namespace.ICService" binding="basicHttpBinding" bindingNamespace="http://www.example.com/" address=""></endpoint>
</service>
</services>

这也是我的服务接口(interface)声明:

[ServiceContract(Namespace = "http://www.example.com/")]
public interface ICService
{
[OperationContract]
[WebInvoke(UriTemplate = "/CPlano",
BodyStyle = WebMessageBodyStyle.Wrapped,
Method = "POST")]
RespuestaCotizador CPlano(int idUsuario, string usuario, string pass, int modalidad, int servicio,
int medicion, string paisDestino, int envio, decimal peso, decimal largo, decimal ancho, decimal alto);
}

最后是我的响应类:

[DataContract(Namespace = "http://www.example.com/")]
public class RespuestaCotizador
{
[DataMember]
public bool HasError;
[DataMember]
public string ErrorMessageESP;
[DataMember]
public string ErrorMessageENG;
[DataMember]
public decimal PrecioCotizado;

public RespuestaCotizador()
{
HasError = false;
ErrorMessageESP = string.Empty;
ErrorMessageENG = string.Empty;
PrecioCotizado = 0;
}
}

我正在使用 Unity 进行依赖注入(inject),但这似乎不相关。

即使我在本地运行服务,我也可以到达第一个断点。

最佳答案

您想使用 SOAP 还是 REST?如果您想使用 SOAP,请使用其他绑定(bind),例如 BasicHttpBinding。 WebHttpBinding 通常用于 REST 服务。如果您想使用 REST,您可以创建一个封装所有内容的类,例如 idUsuario 和 usuario。配置服务方法以接受单个参数:您的新类。然后,在执行 POST 时,您传递一个序列化对象作为请求正文。此外,您不能使用 WCF 测试客户端来使用 REST 服务。它只支持 SOAP。不过,您可以使用 Fiddler。或者(建议用于新服务),使用 ASP.NET Web API 而不是 WCF 来构建 REST 服务。

关于wcf - 无法通过邮件到达 WCF 休息端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11621717/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com