2012-07-06 37 views
1

在Visual Studio 2010中,我試圖連接到我編寫的Web服務。我試圖在我的WPF解決方案中包含Web服務項目,這樣我可以在本地進行調試(如有必要),但是,我也很樂意將Web服務發佈到本地IIS並以此方式連接到它。如何更正我的設置,以便我可以連接到Web服務

這是發生了什麼事。我在我的WPF解決方案中包含了Web服務項目,所以我有兩個項目:WPF和WCF Web服務。我嘗試通過打開「添加服務引用」對話框並單擊「發現」按鈕來向WPF項目添加服務引用。在地址欄中,出現此URI:

http://localhost:49185/MyAppSqlServerProvider.svc 

我給服務在命名空間文本框中輸入一個名稱,然後我點擊「OK」。然後,我收到以下錯誤:

System.InvalidOperationException:無法找到與具有綁定WSHttpBinding的端點匹配scheme 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」端口號被添加到本地主機地址?)

在此先感謝您提供的任何幫助。

回答

0

您需要更改基址以指定「https」而不是「http」。

+0

非常感謝。我嘗試了很多不同的方法,因此我創建了一個不兼容的大雜燴。感謝您的解決方案。 – rogdawg 2012-07-06 15:04:04

+1

沒問題 - 在那裏我自己(可能會再次!) – 2012-07-06 15:04:40

相關問題