簡體   English   中英

從asp.net網站訪問本地自托管WCF服務

[英]access local self-hosted WCF service from asp.net Website

我有一個Windows窗體應用程序中托管的WCF服務庫。 我想從azure網站上托管的asp.net網站調用該服務。 我在網站項目中創建了一個服務引用,並嘗試從后面的代碼中調用某些服務功能。 當我這樣做時,出現以下錯誤:

  An attempt was made to access a socket in a way forbidden by its access permissions 127.0.0.1:8732
    [SocketException (0x271d): An attempt was made to access a socket in a way forbidden by its access permissions 127.0.0.1:8732]
       System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +208
       System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) +464

    [WebException: Unable to connect to the remote server]
       System.Net.HttpWebRequest.GetRequestStream(TransportContext& context) +6543605
       System.Net.HttpWebRequest.GetRequestStream() +13
       System.ServiceModel.Channels.WebRequestHttpOutput.GetOutputStream() +55

    [EndpointNotFoundException: There was no endpoint listening at http://localhost:8732/Design_Time_Addresses/WcfServiceLibrary/ConnectService/ that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.]
       System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +10818447
       System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +336
       TestProject.ConnectServiceReference.IConnectService.SayHello() +0

我的服務正在運行,我可以在瀏覽器中訪問服務地址。 是否可以從網站致電服務?

編輯:

我的服務配置:

<system.serviceModel>
<serviceHostingEnvironment  multipleSiteBindingsEnabled="true" />
<services>
  <service behaviorConfiguration="MyServiceTypeBehaviors" name="WcfServiceLibrary.ConnectService">
    <endpoint address=""
      binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IConnectService" name="ServiceEndpoint" contract="WcfServiceLibrary.IConnectService">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" name="MetaDataEndpoint" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8732/Design_Time_Addresses/WcfServiceLibrary/ConnectService/" />
      </baseAddresses>
    </host>
  </service>
</services>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IConnectService"/>                 
  </basicHttpBinding>     
</bindings>    
 <behaviors>
 <serviceBehaviors>
    <behavior name="MyServiceTypeBehaviors" >
     <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
       <serviceDebug includeExceptionDetailInFaults="False" />
     </behavior>
  </serviceBehaviors>
</behaviors>
</system.serviceModel>

asp.net web.config:

 <bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IConnectService">
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="None" proxyCredentialType="Windows" />
      </security>
    </binding>
  </basicHttpBinding>
  </bindings>
<client>     
  <endpoint address="http://localhost:8732/Design_Time_Addresses/WcfServiceLibrary/ConnectService/" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IConnectService"
    contract="ConnectServiceReference.IConnectService" name="BasicHttpBinding_IConnectService" />
</client>

為了建立您描述的體系結構,您應該查看Azure服務總線,它“允許您在現有(本地)環境中托管WCF服務,並通過在Azure中運行的服務總線將請求委派給這些WCF服務。”

以下Microsoft Azure鏈接概述了您的方案:

Service Bus Relay服務使您可以構建在Azure數據中心和您自己的本地企業環境中運行的混合應用程序。 Service Bus中繼使您能夠安全地將企業網絡中的Windows Communication Foundation(WCF)服務公開到公共雲,而不必打開防火牆連接或對企業網絡基礎結構進行侵入性更改,從而簡化了此過程。

http://azure.microsoft.com/zh-CN/documentation/articles/service-bus-dotnet-how-to-use-relay/

http://blogs.technet.com/b/meamcs/archive/2011/12/23/my-hello-azure-service-bus-wcf-service-step-by-step-guide.aspx

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM