如何更正我的设置,以便我可以连接到Web服务

时间:2012-07-06 14:36:14

标签: wpf wcf web-config

在Visual Studio 2010中,我尝试连接到我编写的Web服务。我试图在我的WPF解决方案中包含Web服务项目,以便我可以在本地调试,如果有必要,但我也很乐意将Web服务发布到我的本地IIS并以这种方式连接到它。

这是发生了什么。我在我的WPF解决方案中包含了Web服务项目,因此,我有两个项目...... WPF和WCF Web服务。我尝试通过打开“添加服务引用”对话框并单击“发现”按钮,为我的WPF项目添加服务引用。在地址栏中,此uri显示:

http://localhost:49185/MyAppSqlServerProvider.svc

我在名称空间文本框中为服务命名,然后单击“确定”。然后,我收到以下错误:

System.InvalidOperationException:找不到与绑定WSHttpBinding的端点的方案https匹配的基址。注册的基地址方案是[http]。

这似乎是一个常见的错误。我发现了很多关于它的帖子,以及如何修复它但是,我无法将这些解决方案应用到我的情况并让它们工作。

以下是我的web.config文件的相关部分

  <system.serviceModel>
<services>
  <service behaviorConfiguration="MyAppDataSync.MyAppSqlServerProviderBehavior"
    name="MyAppDataSync.MyAppSqlServerProvider">
    <endpoint address="" binding="wsHttpBinding" contract="MyAppDataSync.IMyAppSqlServerProvider" bindingConfiguration="wsHttpBindingConfiguration">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost/MyAppSqlServerProvider/"/>
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="MyAppDataSync.MyAppSqlServerProviderBehavior">
      <!-- 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>
<bindings>
  <wsHttpBinding>
    <binding name="wsHttpBindingConfiguration" maxReceivedMessageSize="10485760">
      <readerQuotas maxArrayLength="10485760" />
      <security mode="Transport">
        <transport clientCredentialType="None">
          <extendedProtectionPolicy policyEnforcement="Never" />
        </transport>
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

顺便说一下:我正在使用传输安全性,因为我需要使用会话来进行此服务。 (例如:[ServiceContract(SessionMode = SessionMode.Required)])

如果有人可以告诉我我的设置有什么问题,我会非常感激。 (为什么“49185”端口号被添加到localhost地址?)

提前感谢您提供的任何帮助。

1 个答案:

答案 0 :(得分:0)

您需要更改基地址以指定“https”而不是“http”。