HttpServerChannel.GetUrlsForUri(String) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
傳回具有指定 URI 之物件的所有 URL 的陣列,這 URI 裝載 (Host) 於目前 HttpChannel 上。
public:
virtual cli::array <System::String ^> ^ GetUrlsForUri(System::String ^ objectUri);
public virtual string[] GetUrlsForUri (string objectUri);
abstract member GetUrlsForUri : string -> string[]
override this.GetUrlsForUri : string -> string[]
Public Overridable Function GetUrlsForUri (objectUri As String) As String()
參數
- objectUri
- String
其 URL 被要求之物件的 URI。
傳回
String[]
具有指定 URI 之物件的所有 URL 的陣列,這 URI 裝載於目前 HttpChannel 上。
實作
範例
下列程式碼範例示範如何使用 GetUrlsForUri 方法。 此程式碼範例是針對 類別提供的較大範例的 HttpServerChannel 一部分。
#using <system.dll>
#using <system.runtime.remoting.dll>
using namespace System;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels::Http;
using namespace System::Collections;
public ref class HelloService: public MarshalByRefObject{};
int main()
{
// Create a remotable object.
HttpChannel^ httpChannel = gcnew HttpChannel( 8085 );
WellKnownServiceTypeEntry^ WKSTE = gcnew WellKnownServiceTypeEntry( HelloService::typeid,"Service",WellKnownObjectMode::Singleton );
RemotingConfiguration::RegisterWellKnownServiceType( WKSTE );
RemotingConfiguration::ApplicationName = "HelloServer";
// Print out the urls for HelloServer.
array<String^>^urls = httpChannel->GetUrlsForUri( "HelloServer" );
IEnumerator^ myEnum = urls->GetEnumerator();
while ( myEnum->MoveNext() )
{
String^ url = safe_cast<String^>(myEnum->Current);
System::Console::WriteLine( "{0}", url );
}
return 0;
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels.Http;
class Class1 {
public static void Main() {
// Create a remotable object.
HttpChannel httpChannel = new HttpChannel(8085);
WellKnownServiceTypeEntry WKSTE =
new WellKnownServiceTypeEntry(typeof(HelloService),
"Service",
WellKnownObjectMode.Singleton);
RemotingConfiguration.RegisterWellKnownServiceType(WKSTE);
RemotingConfiguration.ApplicationName = "HelloServer";
// Print out the urls for HelloServer.
string[] urls = httpChannel.GetUrlsForUri("HelloServer");
foreach (string url in urls)
System.Console.WriteLine("{0}", url);
}
}
public class HelloService : MarshalByRefObject{
}
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels.Http
Class SampleClass
Public Shared Sub Main()
' Create a remotable object.
Dim httpChannel As New HttpChannel(8085)
Dim WKSTE As New WellKnownServiceTypeEntry(GetType(HelloService), "Service", WellKnownObjectMode.Singleton)
RemotingConfiguration.RegisterWellKnownServiceType(WKSTE)
RemotingConfiguration.ApplicationName = "HelloServer"
' Print out the urls for HelloServer.
Dim urls As String() = httpChannel.GetUrlsForUri("HelloServer")
Dim url As String
For Each url In urls
System.Console.WriteLine("{0}", url)
Next url
End Sub
End Class
備註
目前的 方法由 ChannelServices.GetUrlsForObject 使用。