试图为将运行Oracle Query并返回结果的方法开具发票但是我收到一个内部错误,我假设根据我在堆栈跟踪中读到的内容与某种转换有关但是我我试图将列表作为字符串。该值是数据库中的varchar2。这是我的堆栈跟踪:
Server stack trace:
at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at IMyService.GetMeterBlinkData()
at MyServiceClient.GetMeterBlinkData()
所以我不确定在这里没有被转换的东西。 我试图在我的代码中使用int i 的值,但这似乎并没有解决我的问题,因为我得到相同的堆栈跟踪。在我到达这一点之前,我可能需要在代码中转换它吗?
这是我的代码:
public List<string> GetMeterBlinkData()
{
List<string> result = new List<string>();
string oradb = "Data Source=********;User Id=****;Password=****;";
OracleConnection conn = new OracleConnection(oradb); // C#
conn.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = "select t2.meternumber, t1.blinkdate, t1.blinkcount from (select * from cecc_processed_blinks where trunc(blinkdate) between to_date('01-may-15', 'dd-mon-yy') and to_date('08-may-15', 'dd-mon-yy')) t1 left join meteraccts t2 on t1.serialnumber = t2.serialnumber order by t1.blinkdate desc";
cmd.CommandType = System.Data.CommandType.Text;
OracleDataReader dr = cmd.ExecuteReader();
dr.Read();
//TODO loop through results and fill the results object
conn.Dispose();
return result;
}
这是我的IMyService.cs:
namespace BlinkDetails
{
[ServiceContract]
public interface IMyService
{
[OperationContract]
List<string> GetMeterBlinkData();
}
}
更新
此时我已使用<serviceDebug includeExceptionDetailInFaults="true" />
启用了日志记录,我现在从WCF测试客户端收到错误,然后服务甚至会运行,说明如下:
System.InvalidOperationException: The contract name 'IMetadataExchange' could not be found in the list of contracts implemented by the service MyService. Add a ServiceMetadataBehavior to the configuration file or to the ServiceHost directly to enable support for this contract.
at System.ServiceModel.Description.ConfigLoader.LookupContract(String contractName, String serviceName)
at System.ServiceModel.Description.ConfigLoader.LoadServiceDescription(ServiceHostBase host, ServiceDescription description, ServiceElement serviceElement, Action`1 addBaseAddress, Boolean skipHost)
at System.ServiceModel.ServiceHostBase.LoadConfigurationSectionInternal(ConfigLoader configLoader, ServiceDescription description, ServiceElement serviceSection)
at System.ServiceModel.ServiceHost.ApplyConfiguration()
at System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection baseAddresses)
at System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses)
at Microsoft.Tools.SvcHost.ServiceHostHelper.CreateServiceHost(Type type, ServiceKind kind)
at Microsoft.Tools.SvcHost.ServiceHostHelper.OpenService(ServiceInfo info)
以下是app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<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 name="BlinkDetails.MyService" behaviorConfiguration="debug">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8733/Design_Time_Addresses/BlinkDetails/Service1/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address="" binding="basicHttpBinding" contract="BlinkDetails.IMyService">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<!-- Metadata Endpoints -->
<!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
<!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="debug">
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior>
<!-- To avoid disclosing metadata information,
set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="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>
</system.serviceModel>
</configuration>
答案 0 :(得分:0)
错误消息表明问题出在您的端点定义中 - 合同= “IMetadataExchange接口”
将此更改为合同的完全限定名称 合同= “BlinkDetails.IMyService”