ヘルプ。私は、HttpWebRequestを使用してサービスバス中継エンドポイントに公開されているWCFサービスにアクセスしようとしていました。HttpWebRequestを使用してAzureサービスバスリレー(WCFエンドポイント)を接続してください
OAuth WRAPプロトコル経由でACSからトークンを取得できました。このトークンをリクエストヘッダーの承認として使用して、WebHttpRelayBindingとして構成されたエンドポイントとOperationContractAttributeおよびWebGetAttributeが適用されたWCFサービスメソッドでWCFサービスと通信するためのWebRequestを作成しました。これは、以前のエラーを解決しますが
[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
:私はサービスクラスに次の属性を適用する提案をGoogleで検索し、見つかった
The message with To ' https://namespace.servicebus.windows.net/Student/GetInfo/GetStudentInfo/1 ' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher. Check that the sender and receiver's EndpointAddresses agree.
:私は、クライアントアプリケーションを実行すると、私はエラー以下しまっ
クライアントアプリケーションは次のエラーで終了します。
The message with Action 'GET' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).
私はWCFのサービス側に何か不足していると思います。お客様のレビューのためにクライアントコードとサービスコードの両方を共有します。
WCFサービスコード:最後に行うの
static void Main(string[] args)
{
var studentId = "1";
string _token = GetToken();
Console.WriteLine(_token);
// Create and configure the Request
var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://namespace.servicebus.windows.net/Student/GetInfo/GetStudentInfo/" + studentId);
httpWebRequest.ContentType = "text/json";
httpWebRequest.Method = "GET";
httpWebRequest.Headers.Add(HttpRequestHeader.Authorization, string.Format("WRAP access_token=\"{0}\"", _token));
// Get the response using the Request
HttpWebResponse response = httpWebRequest.GetResponse() as HttpWebResponse;
// Read the stream from the response object
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
// Read the result from the stream reader
string result = reader.ReadToEnd();
Console.WriteLine("Result: " + result);
Console.ReadLine();
}
static string GetToken()
{
string base_address = string.Format("https://namespace-sb.accesscontrol.windows.net");
string wrap_name = "owner";
string wrap_password = "key";
string wrap_scope = "http://namespace.servicebus.windows.net/";
WebClient client = new WebClient();
client.BaseAddress = base_address;
NameValueCollection values = new NameValueCollection();
values.Add("wrap_name", wrap_name);
values.Add("wrap_password", wrap_password);
values.Add("wrap_scope", wrap_scope);
byte[] responseBytes = client.UploadValues("WRAPv0.9", "POST", values);
string response = Encoding.UTF8.GetString(responseBytes);
string token = response.Split('&')
.Single(value => value.StartsWith("wrap_access_token="))
.Split('=')[1];
string _token = HttpUtility.UrlDecode(token);
return _token;
}