2011-02-04 21 views
5

Trường hợp ngoại lệ:WCF - Binary Encoding qua HTTP ném client và dịch vụ ràng buộc không phù hợp ngoại lệ

Content Loại application/xà phòng + msbin1 không được hỗ trợ bởi dịch vụ http://localhost:1500/MyService.svc. Các ràng buộc khách hàng và dịch vụ có thể là không khớp.

Cấu hình client:

<system.serviceModel> 
    <bindings> 

    <customBinding> 
     <binding name="NetHttpBinding" closeTimeout="00:01:00" 
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"> 
      <binaryMessageEncoding /> 
      <httpTransport allowCookies="false" bypassProxyOnLocal="false" 
         hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" 
         maxBufferPoolSize="524288" maxReceivedMessageSize="65536" 
         transferMode="Buffered" useDefaultWebProxy="true" /> 
     </binding> 
     </customBinding> 

    </bindings> 
    <client> 
     <endpoint address="http://localhost:1500/MyService.svc" 
     binding="customBinding" bindingConfiguration="NetHttpBinding" 
     contract="APP.BLL.IMyServiceContract" name="MyServiceEndpoint" /> 
    </client> 
    </system.serviceModel> 

Cấu hình máy chủ:

<system.serviceModel> 
    <bindings> 
     <customBinding> 
     <binding name="NetHttpBinding" closeTimeout="00:01:00" 
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"> 
      <binaryMessageEncoding /> 
      <httpTransport allowCookies="false" bypassProxyOnLocal="false" 
         hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" 
         maxBufferPoolSize="524288" maxReceivedMessageSize="65536" 
         transferMode="Buffered" useDefaultWebProxy="true" /> 
     </binding> 
     </customBinding> 
    </bindings> 

    <services> 
     <service name="MyAppService"> 
     <endpoint address="" binding="customBinding" bindingConfiguration="NetHttpBinding" 
        contract="APP.BLL.IMyServiceContract"> 
     </endpoint> 
     </service> 
    </services> 

    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <!-- 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> 

    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 

    </system.serviceModel> 
+0

Dịch vụ có được lưu trữ trong IIS hoặc ứng dụng lưu trữ khác không? –

+0

Tôi đã lưu trữ nó bên trong Visual Studio ngay bây giờ. Máy chủ web tích hợp (Tôi không bao giờ có thể nhớ tên của nó). Tôi sẽ triển khai nó cho IIS khi hoàn tất. – mbursill

+0

Tôi gặp vấn đề tương tự nếu máy chủ [endpoint ** Contract **] (http://msdn.microsoft.com/en-us/library/system.servicemodel.description.serviceendpoint.contract.aspx) không khớp với hợp đồng thực tế được sử dụng bởi điểm cuối. – SliverNinja

Trả lời

4

Bạn không thể sử dụng binaryMessageEncodingHTTP mà không customBindings. Bạn có thể sử dụng textMessageEncoding hoặc mtomMessageEncoding ngoài hộp.

Xem bài đăng trên blog này cho reference on using customBindings with HTTP transport.

<bindings> 
    <customBinding> 
     <binding name="basicHttpBinaryBinding"> 
     <binaryMessageEncoding />    
     <httpTransport /> 
     </binding> 
    </customBinding> 
</bindings> 
+3

Điều đó mâu thuẫn với những gì tôi đã đọc trên một số trang web: http://jeffbarnes.net/blog/post/2007/02/22/WCF-Enable-Binary-Encoding-Over-Http.aspx Bạn có một bài viết không mà nói về điều này? – mbursill

+1

HTTP là giao thức dựa trên văn bản. MTOM được thiết kế đặc biệt để thêm các tệp đính kèm nhị phân (giao thức DIME cũ) vào HTTP. Bộ mã hóa nhị phân yêu cầu luồng nhị phân không phải là luồng văn bản. –

+0

@mbursill - Tôi đã cập nhật câu trả lời để phản ánh khả năng thử nghiệm. Bạn có thể lấy kiểu nội dung 'application/soap + msbin1' bằng cách sử dụng cấu hình' customBinding'. [Jeff Barnes đăng bài] (http://jeffbarnes.net/blog/post/2007/02/22/WCF-Enable-Binary-Encoding-Over-Http.aspx) là chính xác. – SliverNinja

Các vấn đề liên quan