2008-10-29 39 views
5

WCF Service của tôi sử dụng wsHttpBinding và hoạt động tốt từ khách hàng khi dịch vụ được gerenated bởi các khách hàng sử dụng các tùy chọn mặc định như sau:WCF - thay đổi kết quả địa chỉ endpoint trong SecurityException

RServiceClient R = new RServiceClient(); 

Tuy nhiên, tại một số điểm tôi sẽ cần để có thể xác định vị trí của dịch vụ, có lẽ bằng cách thay đổi địa chỉ điểm cuối như sau:

RServiceClient R = new RServiceClient(); 
R.Endpoint.Address = new EndpointAddress(new Uri "http://xxx.xxxx.xxx:80/RServer/RService.svc")); 

Tuy nhiên, khi tôi làm rõ các thiết bị đầu cuối chính xác, tôi nhận được một SecurityNegotiationException: System.ServiceModel. S ecurity.SecurityNegotiationException được unhandled Message = "Người gọi không được xác thực bởi dịch vụ." Nguồn = "mscorlib" ....

Dịch vụ WCF chạy trên IIS và có quyền truy cập vô danh được bật trong quản trị viên IIS. Ngoài ra, lỗi này xảy ra khi máy khách chạy từ cùng một máy với dịch vụ dưới tài khoản quản trị viên - tôi không đến được phần đáng sợ khi chạy nó qua mạng!

Bất kỳ ý tưởng nào?

Trả lời

8

Theo mặc định, wsHttpBinding sử dụng xác thực Windows. Tôi không chắc chắn làm thế nào lưu trữ trong IIS ảnh hưởng đến kịch bản đó.

Nếu bạn không muốn bảo mật được bật, bạn có thể thêm yếu tố bảo mật và đặt thành phần chế độ thành "Không" thành cấu hình ở cả hai đầu để tắt cài đặt mặc định.

Tôi nghĩ rằng điều này có thể làm các trick - Tôi đã thêm phần cho wsHttpBinding và thiết lập bindingConfiguration dịch vụ của bạn để trỏ đến các tính chất ràng buộc mới được bổ sung:

<system.serviceModel> 
    <bindings> 
     <wsHttpBinding> 
     <binding name="wsHttpBind"> 
      <security mode="None"> 
      <transport clientCredentialType="None" protectionLevel="EncryptAndSign" /> 
      <message clientCredentialType="None" algorithmSuite="Default" /> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 
    <services> 
     <service behaviorConfiguration="ServiceBehavior" 
      name="RService"> 
      <endpoint address="" 
       binding="wsHttpBinding" 
       bindingConfiguration="wsHttpBind" 
       name="RService" 
       contract="IRService"> 
       <identity> 
        <dns value="localhost" /> 
       </identity> 
      </endpoint> 
      <endpoint address="mex" 
       binding="mexHttpBinding" 
       name="MetadataExchange" 
       contract="IMetadataExchange" /> 
     </service> 
    </services> 
    <behaviors> 
     <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> 
</system.serviceModel> 
+0

Nhờ một tấn ... lưu tôi;) – kape123

0

Bạn đang sử dụng MessageSecurity với chứng chỉ? điều này có thể là một vấn đề chứng chỉ (hostname sai, chứng chỉ tự ký không được cài đặt, vv ..)

0

Dưới đây là thông tin cấu hình dịch vụ của tôi, tôi đang sử dụng wsHttpBinding:

<system.serviceModel> 
    <services> 
    <service behaviorConfiguration="ServiceBehavior" name="RService"> 
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="" 
name="RService" contract="IRService"> 
<identity> 
    <dns value="localhost" /> 
</identity> 
</endpoint> 
<endpoint address="mex" binding="mexHttpBinding" name="MetadataExchange" 
contract="IMetadataExchange" /> 
    </service> 
</services> 
    <behaviors> 
     <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> 
</system.serviceModel> 
3

việc kiểm tra này từ cấu hình của bạn :

...  
    <identity> 
     <dns value="localhost" /> 
    </identity> 
... 

afaik wsHttpBinding có an ninh nhắn bật theo mặc định. và khi nó kiểm tra giá trị dns "localhost", nó không thành công.

0

Xóa khối sắc đã không làm việc, mặc dù đã làm cho tôi một ý tưởng: Nếu tôi thay đổi địa chỉ endpoint từ:

 R.Endpoint.Address = new EndpointAddress(new Uri("http://bigpuss.homeip.net/RServer/RService.svc")); 

để

 R.Endpoint.Address = new EndpointAddress(new Uri("http://localhost/RServer/RService.svc")); 

sau đó tất cả mọi thứ hoạt động tốt! Soo, rõ ràng là khó chịu về địa chỉ url không địa chỉ. Có bất kỳ khu vực nào khác trong cấu hình nơi thiết lập bảo mật không?

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