4

当我尝试调用我开发的 WCF 服务时,我收到此错误消息:“方法或操作未实现”。

让我解释一下我所面临的情况,我会给你更多的细节,代码等:

我正在 Windows 8/Visual Studio 2012 机器中的 .NET 框架 4.0 中开发 WCf 服务。WCF 服务将通过在 .NET compact framework 2.0 中开发的移动应用程序访问(开发环境:运行 Windows XP service pack 3、Visual Studio 2008、Windows Mobile 6.1 Professional Emulator 的虚拟机)。

WCF 服务使用 SAP .NET Conector (SAPnCO) 3.0 版。

当我使用 VS 集成的 IIS 或 IIS8 运行服务时,一切正常:我可以测试服务,从测试控制台应用程序访问它,还可以从 Windows Mobile Emulator 访问它。

然而,我们即将开始对最终用户进行一些初步测试,我们仍然没有合适的服务器来部署 WCF 应用程序,所以我不得不使用 Windows XP 和 IIS express 7.5 制作一个应急服务器(我无法使其在 IIS 5.1 上工作)。

我知道 IIS Express 仅用于本地访问,但我按照本教程将 ti 打开到 LAN:TUTORIAL

这样做我可以通过浏览器访问服务签名并查看 WSDL 文件。

每次我尝试访问该服务时,我都会收到错误消息“方法或操作未实现”。在过去的 4 个小时里,我一直在互联网上寻找一些类似的问题,但没有成功。

这是我到目前为止所做的事情:

  • 在 IIS Express 7.5 上托管默认 WCF 示例服务并远程使用该服务:好的;
  • 将原始服务的范围缩小到最小:仍然得到相同的错误;

所以,我仍然不知道是什么导致了这个或如何解决它。我恳请您的帮助,拜托!

这是我的代码:

网页配置

<?xml version="1.0"?>
<configuration>
  <configSections>
    <sectionGroup name="SAP.Middleware.Connector">
      <sectionGroup name="ClientSettings">
        <section name="DestinationConfiguration" type="SAP.Middleware.Connector.RfcDestinationConfiguration, sapnco"/>
      </sectionGroup>
    </sectionGroup>
  </configSections>
  <SAP.Middleware.Connector>
    <ClientSettings>
      <DestinationConfiguration>
        <destinations>
          <add NAME="QA" USER="XX" PASSWD="XX" CLIENT="XX" LANG="XX" ASHOST="XX" SYSNR="XX" MAX_POOL_SIZE="XX" IDLE_TIMEOUT="XX"/>
        </destinations>
      </DestinationConfiguration>
    </ClientSettings>
  </SAP.Middleware.Connector>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
  <appSettings/>
  <system.web>
    <compilation targetFramework="4.0" debug="true"/>
    <httpRuntime/>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <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="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https"/>
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true"/>
      </system.webServer>
    </configuration>

服务

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

using SAP.Middleware.Connector;

namespace WCFCriarOT
{

    public class Service1 : IService1
    {

        public string CriarOT(int areaSelecionada, int nlenr, string codMaterial, int qtdMAterial)
        {
            try
            {


                string vltyp = "", vlpla = "";

                switch (areaSelecionada)
                {
                    case 1:
                        vltyp = "902";
                        vlpla = "GR-ZONE";
                        break;
                    case 3:
                        vltyp = "901";
                        vlpla = "GFI-ZONE";
                        break;
                    case 4:
                        vltyp = "904";
                        vlpla = "DEVOLUCAO";
                        break;
                    default:
                        break;
                }

                RfcDestination SapRfcDestination = RfcDestinationManager.GetDestination("QA");
                RfcRepository SapRfcRepository = SapRfcDestination.Repository;
                IRfcFunction FCriarOT = SapRfcRepository.CreateFunction("ZWM001");

                FCriarOT.SetValue("I_LGNUM", "WM1");
                FCriarOT.SetValue("I_BWLVS", "999");
                FCriarOT.SetValue("I_MATNR", codMaterial);
                FCriarOT.SetValue("I_WERKS", "120");
                FCriarOT.SetValue("I_LGORT", "0001");
                FCriarOT.SetValue("I_ANFME", qtdMAterial);
                FCriarOT.SetValue("I_SQUIT", "");
                FCriarOT.SetValue("I_VLTYP", vltyp);
                FCriarOT.SetValue("I_VLPLA", vlpla);
                FCriarOT.SetValue("I_VLENR", "");
                FCriarOT.SetValue("I_NLTYP", "");
                FCriarOT.SetValue("I_NLPLA", "");
                FCriarOT.SetValue("I_NLENR", nlenr.ToString().PadLeft(20, '0'));
                FCriarOT.SetValue("I_BNAME", "PAGOTR"); // receber os dados do login posteriormente

                FCriarOT.Invoke(SapRfcDestination);

                if (Convert.ToInt32(FCriarOT.GetValue("E_RETURN")) == 1)
                {
                    IRfcTable RfcReturn = FCriarOT.GetTable("T_MSG");
                    RfcReturn.CurrentIndex = 0;



                    return "1";
                }
                else
                {


                    return "0";
                }
            }
            catch (Exception ex)
            {
                throw new NotImplementedException();

            }
        }
    } 

服务签名

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace WCFCriarOT
{

    [ServiceContract]
    public interface IService1
    {
        // Contrato para a operação "Criar OT"
        [OperationContract]
        string CriarOT(int areaSelecionada, int nlenr, string codMaterial, int qtdMAterial);

        [OperationContract]
        string GetData(int value);

        [OperationContract]
        CompositeType GetDataUsingDataContract(CompositeType composite);

        // TODO: Add your service operations here
    }
    }

例外

System.ServiceModel.FaultException`1 was unhandled
  HResult=-2146233087
  Message=O método ou a operação não está implementada.
  Source=mscorlib
  StackTrace:
    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 testeDoTeste1.ServiceReference1.IService1.CriarOT(Int32 areaSelecionada, Int32 nlenr, String codMaterial, Int32 qtdMAterial)
       at testeDoTeste1.ServiceReference1.Service1Client.CriarOT(Int32 areaSelecionada, Int32 nlenr, String codMaterial, Int32 qtdMAterial) in c:\Users\Documents\Visual Studio 2012\Projects\testeDoTeste1\testeDoTeste1\Service References\ServiceReference1\Reference.cs:line 119
       at testeDoTeste1.Program.Main(String[] args) in c:\Users\Documents\Visual Studio 2012\Projects\testeDoTeste1\testeDoTeste1\Program.cs:line 16
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

如果我未能提供所有必要的信息,请告诉我:我会尽我所能提供。我真的需要并感谢您的所有帮助!非常感谢!

--------------

更新 1

由于 WEB.CONFIG 文件是为使 WCF 服务与 IIS Express 一起工作而编辑的唯一服务部分,我认为这可能(最终)成为麻烦的根源。我发布了原始的 WEB.CONFIG 文件,没有进行编辑,希望这可以帮助某人发现问题!

<?xml version="1.0"?>
<configuration>
  <configSections>
    <sectionGroup name="SAP.Middleware.Connector">
      <sectionGroup name="ClientSettings">
        <section name="DestinationConfiguration" type="SAP.Middleware.Connector.RfcDestinationConfiguration, sapnco"/>
      </sectionGroup>
    </sectionGroup>
  </configSections>
  <SAP.Middleware.Connector>
    <ClientSettings>
      <DestinationConfiguration>
        <destinations>
          <add NAME="QA" USER="XX" PASSWD="XX" CLIENT="XX" LANG="XX" ASHOST="XX" SYSNR="XX" MAX_POOL_SIZE="XX" IDLE_TIMEOUT="XX"/>
        </destinations>
      </DestinationConfiguration>
    </ClientSettings>
  </SAP.Middleware.Connector>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
  <appSettings/>
  <system.web>
    <compilation targetFramework="4.0" debug="true"/>
    <httpRuntime/>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <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="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https"/>
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true"/>
  </system.webServer>
</configuration>

--------------

更新 2

发现了一个新错误,但对我来说仍然很模糊:“{“无法获取目标 QA——没有注册目标配置”}”。这个目的地在开发中运行良好,那么为什么它不能在 IIS Express 上运行呢?

无论如何,这是完整的例外:

System.ServiceModel.FaultException`1 was unhandled
  HResult=-2146233087
  Message=Cannot get destination QA -- no destination configuration registered
  Source=mscorlib
  StackTrace:
    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.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
       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 testeDoTeste1.ServiceReference1.IService1.CriarOT(Int32 areaSelecionada, Int32 nlenr, String codMaterial, Int32 qtdMAterial)
       at testeDoTeste1.ServiceReference1.Service1Client.CriarOT(Int32 areaSelecionada, Int32 nlenr, String codMaterial, Int32 qtdMAterial) in c:\Users\Documents\Visual Studio 2012\Projects\testeDoTeste1\testeDoTeste1\Service References\ServiceReference1\Reference.cs:line 119
       at testeDoTeste1.Program.Main(String[] args) in c:\Users\Documents\Visual Studio 2012\Projects\testeDoTeste1\testeDoTeste1\Program.cs:line 16
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

--------------

4

2 回答 2

3

我发现,如果未加载 sapnco 程序集,则会发生此异常。尝试将引用的 SAP 程序集设置为 Copy local: True。

这不是理想的解决方案,但对我来说效果很好。

于 2013-12-11T09:01:31.423 回答
0

我通过将 configSections 部分移动到 app.config 的顶部来解决它。也许“configSections”必须是配置的第一个子部分。

也见这里: 参数“sectionGroupName”无效

于 2021-08-04T12:35:33.740 回答