就像这个Question
一样由于元数据我无法继续。 它仍然不适合我。我更改了localhost号码
address="http://localhost:54786/AdventureWorksService/mex"
其余的我离开了它是怎么回事但它没有用...在APP.CONFIG或WEB.CONFIG中尝试过...我试着添加<system.serviceModel>...</system.serviceModel>
我仍然收到元数据错误。如果可能的话,请帮我详细解决。
这是 web.config
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime tar
getFramework="4.5" />
</system.web>
<connectionStrings>
<add name="AdventureWorks2012Entities" connectionString="metadata=res://*/AdventureWorksModel.csdl|res://*/AdventureWorksModel.ssdl|res://*/AdventureWorksModel.msl;provider=System.Data.SqlClient;provider connection string="data source=(localdb)\Projects;initial catalog=AdventureWorks2012;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
<system.webServer>
<directoryBrowse enabled="true" showFlags="Date,Time,Extension,Size" />
</system.webServer>
</configuration>
这是 app.config
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<!--<system.serviceModel>-->
<services>
<service name="AdventureWorksService"
behaviorConfiguration="metadataSupport">
<endpoint
address="http://localhost:54786/AdventureWorksService/mex"
binding="mexHttpBinding"
contract="IMetadataExchange"
/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="metadataSupport">
<serviceMetadata/>
</behavior>
</serviceBehaviors>
</behaviors>
<!--</system.serviceModel>-->
</configuration>
答案 0 :(得分:1)
问题中缺少一些信息,但我会猜测一下。
您不会公开元数据,这反过来会阻止您添加服务引用。对于托管服务的应用程序,请仔细检查配置(httpGetEnabled="true"
)中是否为web.config
。如果您使用的是HTTPS
,请使用httpsGetEnabled="true"
切换元素。如果需要,您可以将两者合并。
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
编辑:如果您尝试在浏览器中打开指定的服务网址,则会收到一条明确的消息。
<强> EDIT2:强>
您需要包含服务行为,并且需要包含合同的服务端点。 name
属性指的是服务实现。服务的命名空间,包括服务名称但没有.svc文件扩展名。 contract
属性是指合约界面,当您选择新的wcf服务时,该界面也会创建。
<system.serviceModel>
<services>
<service
name="MyApp.Services.MyService"
behaviorConfiguration="MyServiceBehavior">
<endpoint address=""
binding="wsHttpBinding"
contract="MyApp.Services.IMyService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" /> <!-- Set this to true to return exception details to the calling client. -->
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
尝试添加此配置并编辑相应的属性,然后在Web浏览器中打开该服务。当您通过Visual Studio中的app.config
添加服务时,客户端应自动更新Add Service Reference
。