C# 从asp.net网站访问本地自托管WCF服务
我在Windows窗体应用程序中托管了一个WCF服务库。我想从托管在azure网站上的asp.net网站调用该服务。我在网站项目中创建了一个服务引用,并尝试从代码隐藏中调用一些服务功能。 当我这样做时,我得到以下错误:C# 从asp.net网站访问本地自托管WCF服务,c#,asp.net,wcf,azure,C#,Asp.net,Wcf,Azure,我在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 attem
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链接概述了您的场景: 服务总线中继服务使您能够构建在Azure数据中心和您自己的本地企业环境中运行的混合应用程序。服务总线中继通过使您能够安全地将驻留在企业企业网络中的Windows通信基础WCF服务公开到公共云,而不必打开防火墙连接或需要对企业网络基础设施进行侵入性更改,从而促进了这一点。p>
您正在尝试从Azure连接到localhost?这似乎是一个候选人