LINQ和Web服务问题 [英] LINQ and Web Service Issue

查看:54
本文介绍了LINQ和Web服务问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
我是Web服务(和LINQ)的新手,并且正在兜圈子,试图弄清楚这个问题.
当我在本地主机上运行该服务时,我的服务运行良好,并且当我使用另一台PC上的本地运行的服务时,也没有问题.但是,当我尝试使用IIS使用服务时,仅使用LINQ的函数(字符串函数被成功使用)消耗了问题.我的错误消息是:

Hello,
I am new to Web Services (and LINQ) and am going in circles trying to figure this issue out.
I have a service that works fine when I run it on local host and also I have no issue when I consume the locally running service from another pc. However, when I try to consume the service using IIS, I am having issues consuming only the function that uses LINQ (string functions are successfully consumed). My error message is :

+		ex	{"Unable to cast object of type 'WhereSelectEnumerableIterator`2[VB$AnonymousType_0`2[System.Data.DataRow,System.String],System.String]' to type 'System.Collections.Generic.List`1[ClientServ.Characteristics]'."}	System.Exception


在我的服务中访问的.dll代码如下所示:


My .dll code that is accessed in my service looks like this :

Dim query = (From chars In dtChar.AsEnumerable() _
                            Select New Characteristics With { _
                            .Description = chars.Field(Of String)("Description"), _
                            .Port = chars.Field(Of String)("port"), _
                             .Index = chars.Field(Of String)("index1"), _
                             .Index2 = chars.Field(Of String)("index2")}).ToList
                             Getcharacteristics = query


我的服务合同:


My service contract:

<OperationContract()> _
    Function S_GetChar(ByVal strServer As String, _
                                   ByVal fromDate As Date, _
                                   ByVal ToDate As Date, _
                                   ByVal arrEntities As String, _
                                   Optional ByVal index As String = "", _
                                   Optional ByVal Frequency As Char = "M", _
                                   Optional ByVal strChars As String = "", _
                                   Optional ByVal NumDigits As Integer = 2, _
                                   Optional ByVal blSuffix As Integer = 1, _
                                   Optional ByVal ErrorMsg As Integer = 0, _
                                   Optional ByVal PortOnly As Integer = 0) As List(Of ClientServ.Characteristics)


服务范围内的功能:


My function within my service:

Public Function S_GetChar(ByVal strServer As String, _
                                  ByVal fromDate As Date, _
                                  ByVal ToDate As Date, _
                                  ByVal arrEntities As String, _
                                  Optional ByVal index As String = "", _
                                  Optional ByVal Frequency As Char = "M", _
                                  Optional ByVal strChars As String = "", _
                                  Optional ByVal NumDigits As Integer = 2, _
                                  Optional ByVal blSuffix As Integer = 1, _
                                  Optional ByVal ErrorMsg As Integer = 0, _
                                  Optional ByVal PortOnly As Integer = 0) As List(Of ClientServ.Characteristics) Implements IPA_Service1.S_GetChar
        Dim results As New System.Collections.Generic.List(Of ClientServ.Characteristics)
        Dim testChar As New ClientServ.Characteristics
        results = testChar.Getcharacteristics(strServer, fromDate, ToDate, arrEntities, index, Frequency, strChars, NumDigits, blSuffix, ErrorMsg, PortOnly)
        Return results
    End Function


应用配置:


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>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    <services>
      <service name="WCF_PAService.PA_Service1">
        <endpoint address="" binding="wsHttpBinding" contract="WCF_PAService.IPA_Service1">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://hostname-v:8732/Design_Time_Addresses/WCF_PAService/PA_Service1/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <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="True" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

</configuration>


Web.config:


Web.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 name="WCF_PAService.PA_Service1">
        <endpoint address="" binding="wsHttpBinding" contract="WCF_PAService.IPA_Service1">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://hostname-v:8732/Design_Time_Addresses/WCF_PAService/PA_Service1/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <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="True" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

</configuration>


如果有人可以帮忙!我已经花了几个小时在圈子里走!提前非常感谢您!


If someone could please help! I have spent literally hours on this, going in circles! Thank you so much in advance!

推荐答案

AnonymousType_0`2 [System.Data.DataRow,System.String],System.String]'键入"System.Collections" .Generic.List`1 [ClientServ.Characteristics]'.} System.Exception
AnonymousType_0`2[System.Data.DataRow,System.String],System.String]' to type 'System.Collections.Generic.List`1[ClientServ.Characteristics]'."} System.Exception


在我的服务中访问的.dll代码如下所示:


My .dll code that is accessed in my service looks like this :

Dim query = (From chars In dtChar.AsEnumerable() _
                            Select New Characteristics With { _
                            .Description = chars.Field(Of String)("Description"), _
                            .Port = chars.Field(Of String)("port"), _
                             .Index = chars.Field(Of String)("index1"), _
                             .Index2 = chars.Field(Of String)("index2")}).ToList
                             Getcharacteristics = query


我的服务合同:


My service contract:

<OperationContract()> _
    Function S_GetChar(ByVal strServer As String, _
                                   ByVal fromDate As Date, _
                                   ByVal ToDate As Date, _
                                   ByVal arrEntities As String, _
                                   Optional ByVal index As String = "", _
                                   Optional ByVal Frequency As Char = "M", _
                                   Optional ByVal strChars As String = "", _
                                   Optional ByVal NumDigits As Integer = 2, _
                                   Optional ByVal blSuffix As Integer = 1, _
                                   Optional ByVal ErrorMsg As Integer = 0, _
                                   Optional ByVal PortOnly As Integer = 0) As List(Of ClientServ.Characteristics)


服务范围内的功能:


My function within my service:

Public Function S_GetChar(ByVal strServer As String, _
                                  ByVal fromDate As Date, _
                                  ByVal ToDate As Date, _
                                  ByVal arrEntities As String, _
                                  Optional ByVal index As String = "", _
                                  Optional ByVal Frequency As Char = "M", _
                                  Optional ByVal strChars As String = "", _
                                  Optional ByVal NumDigits As Integer = 2, _
                                  Optional ByVal blSuffix As Integer = 1, _
                                  Optional ByVal ErrorMsg As Integer = 0, _
                                  Optional ByVal PortOnly As Integer = 0) As List(Of ClientServ.Characteristics) Implements IPA_Service1.S_GetChar
        Dim results As New System.Collections.Generic.List(Of ClientServ.Characteristics)
        Dim testChar As New ClientServ.Characteristics
        results = testChar.Getcharacteristics(strServer, fromDate, ToDate, arrEntities, index, Frequency, strChars, NumDigits, blSuffix, ErrorMsg, PortOnly)
        Return results
    End Function


应用配置:


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>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    <services>
      <service name="WCF_PAService.PA_Service1">
        <endpoint address="" binding="wsHttpBinding" contract="WCF_PAService.IPA_Service1">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://hostname-v:8732/Design_Time_Addresses/WCF_PAService/PA_Service1/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <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="True" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

</configuration>


Web.config:


Web.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 name="WCF_PAService.PA_Service1">
        <endpoint address="" binding="wsHttpBinding" contract="WCF_PAService.IPA_Service1">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://hostname-v:8732/Design_Time_Addresses/WCF_PAService/PA_Service1/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <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="True" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

</configuration>


如果有人可以帮忙!我已经花了几个小时在圈子里走!提前非常感谢您!


If someone could please help! I have spent literally hours on this, going in circles! Thank you so much in advance!


这篇关于LINQ和Web服务问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆