【问题标题】:WCF Service for Windows Mobile App running but I cannot connectWindows Mobile 应用程序的 WCF 服务正在运行但我无法连接
【发布时间】:2012-01-30 19:23:41
【问题描述】:

这是我第一次尝试使用 WCF 以及我的第一个 Windows Mobile 应用程序。我一直在关注这个教程:http://msdn.microsoft.com/en-us/library/cc488004(v=vs.90).aspx

我已经创建了一个 WCF 服务,弹出 WCF 服务主机对话框并说服务启动没有错误。然而,当我尝试通过浏览器导航到它时,它不起作用。我正在使用的所有东西都在运行 Windows 7 的本地机器上。

我已禁用所有防火墙。

我在这里不知所措,它说它已启动但我无法导航到它。我尝试时收到 http 400 错误。

元数据地址为http://myip:8731/ElectricReadingCacheSyncService

这是我的配置代码:

<system.serviceModel>
   <services>
      <service name="MiddleTierServiceLibrary.ElectricReadingCacheSyncService" behaviorConfiguration="MiddleTierServiceLibrary.ElectricReadingCacheSyncServiceBehavior">
        <host>
          <baseAddresses>
            <add baseAddress="http://MYIP:8731/ElectricReadingCacheSyncService/"   />
          </baseAddresses>
        </host>
        <endpoint 
            address=""  
            binding="basicHttpBinding"  
            contract="MiddleTierServiceLibrary.IElectricReadingCacheSyncContract">
          <identity>
            <dns value="MYIP"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
     </service>
   </services>
   <behaviors>
      <serviceBehaviors>
        <behavior name="MiddleTierServiceLibrary.ElectricReadingCacheSyncServiceBehavior">
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetai! lInFault s="True" />
        </behavior>
      </serviceBehaviors>
   </behaviors>
</system.serviceModel>

非常感谢任何帮助!

编辑:这是客户端配置

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IElectricReadingCacheSyncContract"
                    closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00"
                    sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false"
                    hostNameComparisonMode="StrongWildcard" maxBufferSize="65536"
                    maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://MYIP:8731/ElectricReadingCacheSyncService/"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IElectricReadingCacheSyncContract"
                contract="IElectricReadingCacheSyncContract" name="BasicHttpBinding_IElectricReadingCacheSyncContract" />
        </client>
    </system.serviceModel>
</configuration> 

【问题讨论】:

  • 您的客户端配置是什么样的?这是服务器端 - 据我所知,它似乎没问题。你正在使用basicHttpBinding - 所以它是一个 SOAP 服务 - 这就是你的目标吗?但是您的客户端配置说明了什么?您是否使用了正确的地址、正确的绑定方式??
  • 作为 SOAP 服务,您不能只在浏览器中导航到该服务并期望在屏幕上显示结果。您要么需要将服务更改为基于 REST 的服务 (webHttpBinding),要么使用像 WCF Test Client 这样的 SOAP 工具来查看和测试您的服务
  • @marc_s:这实际上并不完全正确。您可以通过在浏览器中导航到服务并添加 ?wsdl 来查看服务定义(假设配置正确)。如果您在没有任何参数的情况下导航到 .svc,您实际上会看到一个指向 ?wsdl 页面的链接。我们通常将此作为故障排除的第一步,以确保正确配置 IIS 和 WCF 服务。
  • 您可能会发现在您的服务器上添加服务日志记录会有所帮助:我在这里有一篇关于此的小博文:morestuffabout.net/2011/12/debugging-wcf
  • @competent_tech: 是的 - 当然 - 您可以查看 WSDL - 但您不能实际从浏览器测试 SOAP 服务,例如您无法测试/检查它是否真的返回了正确的结果

标签: c# wcf windows-mobile


【解决方案1】:

您正在向配置中添加基地址:

... 添加 baseAddress="http://MYIP:8731/ElectricReadingCacheSyncService/"/>' ...

对于数据交换,您要添加“mex”:

mex 会附加到您的基地址。在您的浏览器上,转到:

http://MYIP:8731/ElectricReadingCacheSyncService/墨西哥

你应该会看到结果。

【讨论】:

  • 我明白了。我指出,正因为如此,他需要在 url 中包含“mex”。
  • 我知道这不是问题。
猜你喜欢
  • 1970-01-01
  • 2014-08-25
  • 2014-04-28
  • 1970-01-01
  • 1970-01-01
  • 2011-10-05
  • 2015-08-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多