0

私は正常に使用できる Web サービスを持っていますが、URL 経由でパラメーターを入力したい他の誰かと Web サービスを共有しています。

追加した :

<webServices>
      <protocols>
        <add name="HttpGet"/>
      </protocols>
    </webServices>

Web.Config ファイルと SendFile.asmx.cs コードは次のようになります。

    namespace SendFiles
   {
       /// <summary>
       /// Summary description for Service1
       /// </summary>
    [WebService(Namespace = "http://testco.co.za/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class SendFile : System.Web.Services.WebService
    {

        [WebMethod]
        public bool PostToDB(LoadEntity _lead)
        {

            ConnectToSQLDB(ConfigurationManager.AppSettings["Server"],   ConfigurationManager.AppSettings["DB"],
                                ConfigurationManager.AppSettings["UserName"], ConfigurationManager.AppSettings["Password"], ref connectionRef);

            if (LI.ImportFiles(_lead, ref (error)) == true)
            {
                return true;
            }
            else
                return false;
        }

追加してみました:

 [OperationContract]
    [WebGet]
    bool PostToDB(string IDNo, string FName, string SName);

しかし、abstract、extern、または partial とマークされていないため、本体を宣言する必要があるというエラーが表示されます。誰でも助けることができますか?

4

2 に答える 2

1

WCF Rest サービスの作成方法に関するご要望にお応えして...

サービス契約:

[ServiceContract]
public interface ITestService
{
    [WebGet(UriTemplate = "Tester")]
    [OperationContract]
    Stream Tester();
}

実装について

public class TestService : ITestService
{
    public Stream Tester()
    {
        NameValueCollection queryStringCol = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters;

        if (queryStringCol != null && queryStringCol.Count > 0)
        {
            string parameters = string.Empty;
            for (int i = 0; i < queryStringCol.Count; i++)
            {
                parameters += queryStringCol[i] + "\n";
            }

            return new MemoryStream(Encoding.UTF8.GetBytes(parameters));
        }
        else
            return new MemoryStream(Encoding.UTF8.GetBytes("Hello Jersey!"));
    }
}

これにより、すべてのクエリ文字列値が単純に出力されます。取得するクエリ文字列パラメーターに応じて、必要な処理を行うことができます。

たとえば、入れる場合。

http://localhost:6666/TestService/Tester?abc=123&bca=234

それからあなたは得るでしょう

123 234

あなたの出力として。

それでも必要な場合は、残りのコードを次に示します。これはコンソール アプリを使用して作成されましたが、簡単に Web に変換できます。実際の輸入品は上記のものです。

class Program
{
    static ServiceHost _service = null;

    static void Main(string[] args)
    {
        _service = new ServiceHost(typeof(TestService));
        _service.Open();

        System.Console.WriteLine("TestService Started...");
        System.Console.WriteLine("Press ENTER to close service.");
        System.Console.ReadLine();

        _service.Close();
    }
}

<configuration>
<startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <services>
      <service name="ConsoleApplication1.TestService">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:6666/TestService"/>
          </baseAddresses>
        </host>
        <endpoint binding="webHttpBinding" contract="ConsoleApplication1.ITestService"
          behaviorConfiguration="webHttp"/>
      </service>      
    </services>
    <bindings>
      <webHttpBinding>
        <binding name="webHttpBinding" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
          <readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647"/>
        </binding>
      </webHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>          
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="webHttp">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>
于 2012-10-25T14:01:39.063 に答える
0

.asmx ページでテスト ハーネスを介してテストすると、どの URL が生成されますか? それを発信者に渡して、発信者があなたと同じ URL を実行できることを確認できますか?

非 .NET クライアントからサービスを使用する他のユーザーが主なユースケースである場合は、WCF REST ベースのサービスをお勧めします。

于 2012-10-24T14:04:13.013 に答える