2012-07-23 56 views
1

我正尝试创建一个以Azure Web角色托管的WCF服务。该服务必须能够通过肥皂和休息到达。无法通过邮政到达WCF休息端点

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

我试图做的是要消耗我的REST端点用了SoapUI项目,做与所有参数的查询字符串一个帖子,但是当我运行这个项目,我得到的回应是:

服务器在处理请求时遇到错误。异常消息是'错误反序列化操作'CPlano'的请求消息体。 OperationFormatter无法反序列化消息中的任何信息,因为消息是空的(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> 

而且,这里是我的服务接口声明:

[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; 
    } 
} 

我使用统一进行依赖注入,但这似乎是n有关。

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

+0

鉴于您看到的异常消息,我不知道SoapUI是否正确设置了对该服务的调用。 WCF正在接收消息并尝试将传入消息更改为CPlano对象,但由于它认为该消息不包含任何信息而失败。您是否尝试过使用Visual Studio附带的WCFTestClient.exe甚至是单独的项目来测试您的服务? SoapUI以外的其他东西排除了SoapUI成为问题? 此外,尝试在模拟器外部运行Web项目(将其设置为启动项目)以排除Azure。 – MikeWo 2012-07-23 23:57:31

+0

嗨!我尝试过使用WCFTestClient ...但我认为它只使用soap端点来调用服务......使用此工具,我从服务中收到了正确答案。 – user1547073 2012-07-24 00:13:09

+0

是的,你和Ming Xu是对的,WCFTest客户端不测试REST端点,但是如果SOAP端点正确回答,那么你已经排除了服务本身的问题,现在你只需要查看REST端点或调用者是问题。当你使用不同的工具时会发生什么(像Ming建议的提琴手,甚至是另一个项目)? – MikeWo 2012-07-27 11:36:45

回答

0

你想使用SOAP还是REST?如果你想使用SOAP,那么使用另一个绑定,比如BasicHttpBinding。 WebHttpBinding通常用于REST服务。如果你想使用REST,你可以创建一个封装类似idUsuario和usuario的类。配置服务方法以接受单个参数:您的新类。然后在执行POST时,将一个序列化对象作为请求主体。另外,您不能使用WCF测试客户端来使用REST服务。它只支持SOAP。但是,您可以使用Fiddler。或者(推荐用于新服务),使用ASP.NET Web API而不是WCF来构建REST服务。