WCF安全错误
问题描述:
我可以用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
如果您的应用程序在部分信任下运行,您可以提供信息吗?什么是您的项目类型的客户端和服务器。你的服务在哪里托管? – Rajesh
我不知道信任设置在哪里,我刚刚创建了一个新的Web浏览器wpf应用程序,并添加了一个按钮,启动了wcf trmplate,并尝试通过提供服务引用来访问它。该项目托管在本地主机上,通过在视觉工作室中按F5键。 – surpavan