外部IP的WCF服务问题

时间:2015-05-29 10:02:26

标签: c# wcf iis

我的WCF应用程序遇到了一个非常奇怪的问题 我有一个IIS托管的WCF服务 这是服务的web.config:

<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.5" />
        <httpRuntime targetFramework="4.5" maxRequestLength="2147483647" executionTimeout="600" />
    </system.web>
    <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior name="SyncWcfServices.MainServiceBehavior">
                    <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="true" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <bindings>
            <wsHttpBinding>
                <binding name="ExtendedMaxSize" maxReceivedMessageSize="2147483647"></binding>
            </wsHttpBinding>
        </bindings>
        <services>
            <service name="SyncWcfServices.MainService" behaviorConfiguration="SyncWcfServices.MainServiceBehavior">
                <endpoint address="" binding="wsHttpBinding" bindingConfiguration="ExtendedMaxSize" contract="SyncWcfServices.IMainService">
                    <identity>
                        <dns value="localhost" />
                    </identity>
                </endpoint>
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
                <host>
                    <baseAddresses>
                        <add baseAddress="http://localhost:8733/Design_Time_Addresses/SyncWcfServices/MainService/" />
                    </baseAddresses>
                </host>
            </service>
        </services>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
</configuration>

它被配置为使用特殊端口号在IIS下运行的网站 该服务的客户端是WPF应用程序。负责服务交互的代码部分:

public BMS_SYNC_DOC[] GetDocuments(POSAuthorizationModel data)
{
    using (var service = this.GetSyncService())
    {
        return service.GetDocuments(data);
    }
}

private MainServiceClient GetSyncService()
{
    var service = new MainServiceClient();
    service.Endpoint.Address = new EndpointAddress(Configuration.SyncServiceUrl);

    return service;
}

在同一网络中使用客户端时,一切正常(例如Configuration.SyncServiceUrl = "192.168.0.111:3333/SyncService.svc"
但是,当我试图从外部网络运行它时,它就失败了 有点像

Configuration.SyncServiceUrl = "25.35.45.55:3333/SyncService.svc".

25.35.45.55是该公司的外部IP地址。我已将端口映射到防火墙上的IIS服务器,当我从Web浏览器打开上面的URL时,我可以看到服务描述。

这是错误的堆栈跟踪:

The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.

Server stack trace: 
   at System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at System.ServiceModel.ICommunicationObject.Close(TimeSpan timeout)
   at System.ServiceModel.ClientBase`1.System.ServiceModel.ICommunicationObject.Close(TimeSpan timeout)
   at System.ServiceModel.ClientBase`1.Close()
   at System.ServiceModel.ClientBase`1.System.IDisposable.Dispose()
   at SyncCore.Helpers.ServiceHelper.GetDocuments(POSAuthorizationModel data)
   at SyncClient.MainWindow.<>c__DisplayClass4.<ReloadData>b__3()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at SyncClient.MainWindow.<ReloadData>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at SyncClient.MainWindow.<Reload>d__0.MoveNext()

我认为在IIS或我的服务配置文件中存在一些配置问题。但我找不到合适的解决方案。

有什么想法吗?

修改
我已经解决了这个问题 在Web.config中更改了安全模式并将clientCredentialType传输到None。

0 个答案:

没有答案
相关问题