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

标签 wcf rest soap azure unity-container

我正在尝试创建在 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/

相关文章:

WCF 自托管 REST 服务器 (https) 不断要求客户端身份验证

c# - 工作几个小时后 wcf 服务方法出错

java - Jersey 1.x 与 jackson : Customising the response JSON

SOAP 响应模式验证

Python 泡沫错误 "' NoneType' 对象没有属性 'promotePrefixes'“

c# - 使用 httpclient postAsJsonAsync 来自 WCF 服务的错​​误请求

wcf - 带有对象列表的数据绑定(bind) Silverlight 组合框 - 工作但丑陋

rest - 使用 ServiceStack 实现 WebHook

wcf - 如何修复 MaxItemsInObjectGraph 错误?

web-services - SOAP 网络服务演变