我在StackOverflow的另一篇文章中关注了这个链接:
这是我的WCF服务库中的app.config。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service behaviorConfiguration="TestClient.Service.Service1Behavior"
name="TestClient.Service.SearchService">
<endpoint address="" behaviorConfiguration="Sample.WsdlSampleEndpointBehavior" binding="basicHttpBinding" bindingConfiguration=""
contract="TestClient.Service.ISearchService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8731/TestClient.Service/Service1/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="Sample.WsdlSampleEndpointBehavior">
<wsdlExtensions location="http://localhost:8731/TestClient.Service/Service1/"/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="TestClient.Service.Service1Behavior">
<!-- 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>
<extensions>
<behaviorExtensions>
<!-- Declare that we have an extension called WSDL Extras-->
<add name="wsdlExtensions" type="WCFExtras.Wsdl.WsdlExtensionsConfig, WCFExtras, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</behaviorExtensions>
</extensions>
</system.serviceModel>
</configuration>
我在这里删除了连接字符串部分等部分。当我尝试使用 [XmlComments] 运行时,它会给我一个错误:
Error: Cannot obtain Metadata from http://localhost:8731/TestClient.Service/Service1/mex
If this is a Windows (R) Communication Foundation service to which you have access,
please check that you have enabled metadata publishing at the specified address.
For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error
URI: http://localhost:8731/TestClient.Service/Service1/mex
Metadata contains a reference that cannot be resolved: 'http://localhost:8731/TestClient.Service/Service1/mex'.
<?xml version="1.0" encoding="utf-16"?>
<Fault xmlns="http://www.w3.org/2003/05/soap-envelope">
<Code><Value>Receiver</Value><Subcode><Value xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:InternalServiceFault</Value></Subcode></Code>
<Reason><Text xml:lang="en-US">An exception was thrown in a call to a WSDL export extension: WCFExtras.Wsdl.Documentation.XmlCommentsAttribute contract: http://tempuri.org/:ISearchService</Text></Reason>
<Detail xmlns:s="http://www.w3.org/2003/05/soap-envelope"><ExceptionDetail xmlns="http://schemas.datacontract.org/2004/07/System.ServiceModel" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<HelpLink i:nil="true"></HelpLink>
<InnerException><HelpLink i:nil="true"></HelpLink><InnerException i:nil="true"></InnerException>
<Message>XML documentation file for TestClient.Service.dll was not found. Make sure the XML documentation option is enabled in the project properties for that assembly.</Message>
<StackTrace>
at WCFExtras.Utils.XmlCommentsUtils.LoadXmlComments(Type type, Boolean throwIfNotFound) in C:\sandbox\WCFExtras\WCFExtras\Utils\XmlCommentsUtils.cs:line 305
at WCFExtras.Wsdl.Documentation.XmlCommentsExporter.ExportContract(WsdlExporter exporter, WsdlContractConversionContext context, XmlCommentFormat format) in C:\sandbox\WCFExtras\WCFExtras\Wsdl\Documentation\XmlCommentsExporter.cs:line 172
at WCFExtras.Wsdl.Documentation.XmlCommentsAttribute.ExportContract(WsdlExporter exporter, WsdlContractConversionContext context) in C:\sandbox\WCFExtras\WCFExtras\Wsdl\Documentation\XmlCommentsAttribute.cs:line 45
at System.ServiceModel.Description.WsdlExporter.CallExtension(WsdlContractConversionContext contractContext, IWsdlExportExtension extension)</StackTrace><Type>System.ApplicationException</Type></InnerException><Message>An exception was thrown in a call to a WSDL export extension: WCFExtras.Wsdl.Documentation.XmlCommentsAttribute contract: http://tempuri.org/:ISearchService</Message><StackTrace>
at System.ServiceModel.Description.ServiceMetadataBehavior.MetadataExtensionInitializer.GenerateMetadata() at System.ServiceModel.Description.ServiceMetadataExtension.EnsureInitialized()
at System.ServiceModel.Description.ServiceMetadataExtension.WSMexImpl.GatherMetadata(String dialect, String identifier)
at System.ServiceModel.Description.ServiceMetadataExtension.WSMexImpl.Get(Message request) at SyncInvokeGet(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</StackTrace>
<Type>System.InvalidOperationException</Type></ExceptionDetail></Detail></Fault>
HTTP GET Error
URI: http://localhost:8731/TestClient.Service/Service1/mex
There was an error downloading 'http://localhost:8731/TestClient.Service/Service1/mex'.
The request failed with HTTP status 400: Bad Request.
答案 0 :(得分:5)
错误信息的内容就在那里:
XML文档文件 找不到TestClient.Service.dll。 确保XML文档选项 在项目属性中启用 对于那个集会。
转到项目选项,在“构建”页面上,启用XML文档的创建。