簡體   English   中英

對於基於 windows 的系統,我如何在 C# 中制作 WCF?

[英]How i can make WCF in C# for windows based System?

我想在 c# 中創建一個 WCF 應用程序或 [應用程序],以響應我通過基於 HTML 的應用程序發送的查詢。

假設我向 url 發送查詢,他們通過調用已經安裝在用戶系統中的 TCP 套接字來回應我。

你能告訴我可以通過 HTML 在本地調用它們嗎? 他們允許他們打電話嗎?

Are i can make a application in HTML, css, javascript who call the WCF and WCF respond the queries.

WCF 是一個支持你提到的所有場景的通信框架。 WCF 可以通過基於 web 的技術和基於 windows 的技術輕松訪問。 ]

編輯

一個文件沒有配置 WCF 服務。

using System.ServiceModel;
using System.ServiceModel.Description;
using System.Runtime.Serialization;
using System;

[ServiceContract]
public interface  AddStuff
{
    [OperationContract]
    int Add(int X,int Y);
}

public class opAddStuff : AddStuff
{
    public int Add(int X, int Y)
    {
        return X + Y;
    }
}

public class Pgm
{
    static void Main(string[] args)
    {
        string httpAddr = "http://127.0.0.1:6001/AddStuff";
        string netAddr= "net.tcp://127.0.0.1:5001/AddStuff";

        System.ServiceModel.ServiceHost SH = new ServiceHost(typeof(opAddStuff),new Uri(httpAddr));

        BasicHttpBinding B = new BasicHttpBinding();
        NetTcpBinding NB = new NetTcpBinding();

        SH.AddServiceEndpoint(typeof(AddStuff), B, httpAddr);
        SH.AddServiceEndpoint(typeof(AddStuff), NB, netAddr);



        System.ServiceModel.Description.ServiceMetadataBehavior smb = SH.Description.Behaviors.Find<ServiceMetadataBehavior>();
       // If not, add one
        if (smb == null)
            smb = new ServiceMetadataBehavior();

        smb.HttpGetEnabled = true;
        smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;

        SH.Description.Behaviors.Add(smb);
        SH.AddServiceEndpoint(  ServiceMetadataBehavior.MexContractName,  MetadataExchangeBindings.CreateMexHttpBinding(),  "mex");

        SH.Open();

        Console.WriteLine("Service at your service");
        string crap = Console.ReadLine();



    }
}

這是一個足夠簡單的起點http://www.codeproject.com/KB/WCF/GettingStartedWithWCF.aspx

如果您想立即開始使用代碼,請在 Visual Studio 中創建一個類型為“WCF 服務應用程序”的新項目。 然后,您將獲得一些可以運行的框架服務。 右鍵單擊 Service.svc 文件 --> 瀏覽。 服務“幫助”(藍色主題)頁面將顯示在 Internet exploere 中,瞧你有一個正在運行的 wcf 服務。

服務的代碼在 Service.svc.cs 文件中,服務實現的契約在 IService.cs 文件中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM