2011-11-22 131 views
0

我可以用wcf作爲windows服務構建一些基本應用程序,只是基本的東西。我正在嘗試製作一個wpf瀏覽器應用程序並將其與wcf一起託管。WCF安全錯誤

當我嘗試從wcf獲取數據時,出現以下錯誤: 'System.Net.WebPermission,System,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'失敗。

以下是我用來訪問數據的代碼:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click 
     Button1.Content = "asdasd" 
     Dim serv As New ServiceReference1.IservClient 
     Button1.Content = serv.DoWork 
    End Sub 

代碼爲WPF瀏覽應用程序的app.config文件:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.diagnostics> 
     <sources> 
      <!-- This section defines the logging configuration for My.Application.Log --> 
      <source name="DefaultSource" switchName="DefaultSwitch"> 
       <listeners> 
        <add name="FileLog"/> 
        <!-- Uncomment the below section to write to the Application Event Log --> 
        <!--<add name="EventLog"/>--> 
       </listeners> 
      </source> 
     </sources> 
     <switches> 
      <add name="DefaultSwitch" value="Information" /> 
     </switches> 
     <sharedListeners> 
      <add name="FileLog" 
       type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" 
       initializeData="FileLogWriter"/> 
      <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log --> 
      <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> --> 
     </sharedListeners> 
    </system.diagnostics> 
    <system.serviceModel> 
     <bindings> 
      <basicHttpBinding> 
       <binding name="BasicHttpBinding_Iserv" 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://localhost:23072/serv.svc" binding="basicHttpBinding" 
       bindingConfiguration="BasicHttpBinding_Iserv" contract="ServiceReference1.Iserv" 
       name="BasicHttpBinding_Iserv" /> 
     </client> 
    </system.serviceModel> 
</configuration> 

代碼WCF的Web配置文件:

<?xml version="1.0"?> 
<configuration> 

    <system.web> 
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.0" /> 
    </system.web> 
    <system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <!-- 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="false"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 

</configuration> 

服務代碼是:

<ServiceContract()> 
Public Interface Iserv 

    <OperationContract()> 
    Function DoWork() As String 

End Interface 

Public Class serv 
    Implements Iserv 

    Public Function DoWork() As String Implements Iserv.DoWork 
     Return "ok" 
    End Function 

End Class 

你能幫我解決這個問題嗎?提前致謝。任何有關替代方法的建議都非常受歡迎。

源文件在 https://skydrive.live.com/?id=d358d316fa2c3a37&sc=documents&uc=1&id=D358D316FA2C3A37%21135# 文件名上傳的是tiko.rar

+0

如果您的應用程序在部分信任下運行,您可以提供信息嗎?什麼是您的項目類型的客戶端和服務器。你的服務在哪裏託管? – Rajesh

+0

我不知道信任設置在哪裏,我剛剛創建了一個新的Web瀏覽器wpf應用程序,並添加了一個按鈕,啓動了wcf trmplate,並嘗試通過提供服務引用來訪問它。該項目託管在本地主機上,通過在視覺工作室中按F5鍵。 – surpavan

回答

0

你可以看看這個link

還要確保您可以從瀏覽器訪問Web服務,也可以看到IE中的wsdl。

+0

我看到了鏈接,並按照此方式遵循:[鏈接] http://www.codeproject.com/KB/WPF/wcfinxbap.aspx但是我得到相同的錯誤,只知道不知道爲什麼。 – surpavan

+0

當您從IE訪問Web服務及其WSDL時,您會得到什麼? – Rajesh

+0

我收到有關'System.Net.WebPermission,System,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'失敗的錯誤消息。 – surpavan